﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pasteles.Controler;
using Pasteles.DataBase;
namespace Pasteles
{
    public partial class CashierUnimportantForm : Form
    {
        ValidateObject validateProcessor = new ValidateObject();
        StringProcessing objStringProcessor = new StringProcessing();
        Connection cnn = new Connection("config.xml");
        DateTime curDate = DateTime.Now;
        public CashierUnimportantForm()
        {
            InitializeComponent();
        }

        private void CashierUnimportantForm_Load(object sender, EventArgs e)
        {

        }
        
        //---------------------------txtPayMoney Event-----------------------------
        private void txtPayMoney_KeyDown(object sender, KeyEventArgs e)
        {
            validateProcessor.validateNum(e);
        }

        private void txtPayMoney_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (validateProcessor.nonNumberEntered)
            {
                e.Handled = true;
            }
        }

        private void txtPayMoney_TextChanged(object sender, EventArgs e)
        {
            objStringProcessor.cutNo(txtPayMoney);
        }
        //--------------------------------------------------------------------------
     
        //-----------------------------btnPayMoney Event----------------------------
        private void btnPayMoney_Click(object sender, EventArgs e)
        {
            string sSubject = txtSubject.Text.ToString();
            long sPayMoney = long.Parse(objStringProcessor.reNo(txtPayMoney.Text.ToString()));
            string sCurdate = curDate.ToString("yyyy-MM-dd HH:mm");
            string sDetails = txtDetails.Text.ToString();

            string sQuery = "insert into chi_lat_vat_tai_quay (MA_PHONG_BAN,MA_NHAN_VIEN,TEN_MUC_CHI,SO_TIEN_CHI_,THOI_GIAN_CHI,CHU_THICH)"+
                "values("+LoginForm.sShopID+","+LoginForm.manv+",'"+sSubject+"',"+sPayMoney+",'"+sCurdate+"','"+sDetails+"');";
            this.insertIntoMySQL(sQuery);
        }
        //--------------------------------------------------------------------------

        //-----------------------------btnReset Event----------------------------
        private void btnReset_Click(object sender, EventArgs e)
        {
            this.emptyFields();
        }
        //--------------------------------------------------------------------------

        //-----------------------------btnCancel Event----------------------------
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //--------------------------------------------------------------------------

        //-----------------------------Object Status--------------------------------
        private void emptyFields()
        {
            txtSubject.Text = "";
            txtDetails.Text = "";
            txtPayMoney.Text = "";
        }
        //--------------------------------------------------------------------------

        //-----------------------------Excecute Query-------------------------------
        private void insertIntoMySQL(string sQuery)
        {
            try
            {
                cnn.excecuteQuery(sQuery);
            }
            catch (Exception error)
            {
                MessageBox.Show("Insert Error: " + error.ToString());
            }
        }

        //--------------------------------------------------------------------------
    }
}
